package cn.pzhu.controller.web;

import cn.pzhu.controller.BaseController;
import cn.pzhu.model.*;
import cn.pzhu.services.web.WebAcheievementServices;
import cn.pzhu.services.web.WebCategoryServices;
import cn.pzhu.services.web.WebLogistics;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by dongp on 2016/5/8.
 */
public class WebAcheievementController extends BaseController {

    private WebCategoryServices categoryServices = new WebCategoryServices();
    private WebAcheievementServices acheievementServices = new WebAcheievementServices();
    private WebLogistics logistics = new WebLogistics();

    public void queryPage(){
        // 获取查询条件参数
        String typeVal = getPara("typeVal","");
        String search = getPara("search","");

        List<Category> categoryList = categoryServices.queryList();
        setAttr("categoryList", categoryList);

        List<Achievement> achievementList = acheievementServices.queryPage(getRequest(),typeVal,search);
        setAttr("achievementList",achievementList);
        render("acheievement/acheievement.jsp");
    }

    public void queryDetail() {
        int id = getParaToInt("id");
        Achievement achievement = acheievementServices.queryDetail(id);
        setAttr("achievement",achievement);
        render("acheievement/acheievementDetail.jsp");
    }

    public void queryForOrder() {
        // 判断用户是否登录
        HttpSession session = getSession();
        User user = (User) session.getAttribute("user");
        if(user == null) {
            redirect("/web/login/login");
            return;
        }

        int userID = user.getInt("userID");
        List<Logistics> logisticList = logistics.queryByUserId(userID);
        setAttr("logisticList",logisticList);
        int id = getParaToInt("id");
        Achievement achievement = acheievementServices.queryDetail(id);
        setAttr("achievement",achievement);
        render("order/order.jsp");
    }
}
